
#include "shape.h"
#include "shapebase.h"
#include "parsersharetool.h"

QMutex ParserShareTool::valuelistmutex;
QMutex ParserShareTool::stringlistmutex;
QMutex ParserShareTool::valuemutex;
QList<QString> ParserShareTool::m_stringlist;
QList<double> ParserShareTool::m_valuelist;
    int ParserShareTool::m_icurnum=0;

    ParserShareTool::ParserShareTool()
    {
        for(int it=0;it<PARSERSHARENUM;it++)
        {
            m_stringlist.push_back("");
            m_valuelist.push_back(0);
        }
    }
    void ParserShareTool::setnum(int inum)
    {
        valuemutex.lock();
        m_icurnum=inum;
        valuemutex.unlock();
    }
    void ParserShareTool::setvalue(double ivalue)
    {
        valuemutex.lock();
        int inum=m_icurnum;
        valuemutex.unlock();

        valuelistmutex.lock();
        m_valuelist[inum]=ivalue;
        valuelistmutex.unlock();
    }

    void ParserShareTool::setnumvalue(double inum,double ivalue)
    {
        valuelistmutex.lock();
        m_valuelist[inum]=ivalue;
        valuelistmutex.unlock();
    }

    void ParserShareTool::setstring(const char * pchar)
    {
        valuemutex.lock();
        int inum=m_icurnum;
        valuemutex.unlock();

        stringlistmutex.lock();
        m_stringlist[inum]=QString(pchar);
        stringlistmutex.unlock();
    }
    void ParserShareTool::addstring(const char * pchar)
    {
        valuemutex.lock();
        int inum=m_icurnum;
        valuemutex.unlock();

        stringlistmutex.lock();
        m_stringlist[inum]=m_stringlist[inum]+QString(pchar);
        stringlistmutex.unlock();
    }
    double ParserShareTool::getvalue()
    {
        valuemutex.lock();
        int inum=m_icurnum;
        valuemutex.unlock();

        valuelistmutex.lock();
        int ivalue = m_valuelist[inum];
        valuelistmutex.unlock();

        return ivalue;
    }
    double ParserShareTool::getnumvalue(int inum)
    {
        valuelistmutex.lock();
        int ivalue = m_valuelist[inum];
        valuelistmutex.unlock();

        return ivalue;
    }

    void ParserShareTool::reset()
    {
        for(int it=0;it<PARSERSHARENUM;it++)
        {
            m_stringlist.push_back("");
            m_valuelist.push_back(0);
        }
    }
    void ParserShareTool::setresult(void * pshape)
    {
        QShape*pashape=(QShape*)pshape;
        if(nullptr!=pshape)
        {
            valuemutex.lock();
            int inum=m_icurnum;
            valuemutex.unlock();

            stringlistmutex.lock();
            m_stringlist[inum]=QString(pashape->result());
            stringlistmutex.unlock();

        }
      }
    void ParserShareTool::addresult(void * pshape)
      {
          QShape*pashape=(QShape*)pshape;
          if(nullptr!=pshape)
          {
              valuemutex.lock();
              int inum=m_icurnum;
              valuemutex.unlock();

              stringlistmutex.lock();
              m_stringlist[inum]=m_stringlist[inum]+QString(pashape->result());
              stringlistmutex.unlock();

          }
      }

      QString ParserShareTool::getstring(int inum)
      {
          stringlistmutex.lock();
          QString astr =  m_stringlist[inum];
          stringlistmutex.unlock();
          return  astr;
      }
